<?php

App::uses('PST_TEXT', 'Presentation');

class PST_CODIGO_INVENTARIO extends PST_TEXT {

    public function renderMaintForm() {
        $html = '<span id="load_inventario"><a href="javascript:void(0);"><img class="link" src="' . WWW . 'img/load.png" /></a></span>';
        $html.= '<span id="change_inventario"><a href="javascript:void(0);">Cambiar</a></span>';
        $html.= '<span id="loading_inventario" style="display: none;"><img src="' . WWW . 'img/loading.gif" width="17" /></span>';
        $html.= '<span id="info_inventario"></span>';
        $this->array['after'] = $html;

        return parent::renderMaintForm();
    }

    protected function getHelperValue() {
        if (empty($this->value)) {
            return $this->loadDbQuery();
        }

        $db = ConnectionManager::getDataSource('default');
        $array = $db->Query("SELECT t.nombre, s.producto 
                             FROM inventario i 
                             LEFT JOIN stock s ON s.id=i.stock_id
                             LEFT JOIN tipos t ON t.id=s.tipo_id
                             WHERE i.id=" . $this->value);
        $array = reset($array);

        return $this->loadDbQuery() . " > " . $array['t']['nombre'] . " > " . $array['s']['producto'];
    }

}